-- STANDARD SCRIPT
-- IT UPDATES THE batch_status_recon_t TABLE SHOWING THE BATCH IS DONE;
--

\set ON_ERROR_STOP 1
CREATE OR REPLACE FUNCTION batch_done_recon_f() RETURNS void AS $$
DECLARE
  v_batch_run_date timestamp;
  v_data_flag varchar(1);
  v_cust_id integer;
BEGIN


-- GETTING PARAMETERS
SELECT INTO v_batch_run_date,v_cust_id,v_data_flag our_run_date,cust_id,data_flag  FROM temp_batch_recon_t limit 1;

IF (v_data_flag = 'U') THEN

      SELECT INTO v_batch_run_date validated_date FROM  temp_batch_recon_t limit 1;

ELSIF (v_data_flag = 'R') THEN

      SELECT INTO v_batch_run_date recon_sent_date FROM  temp_batch_recon_t limit 1;

END IF;




PERFORM ml_upd_batch_status_recon_new_f(v_cust_id,v_batch_run_date,3,0,'BATCH DONE');

  RETURN;

END;
$$ LANGUAGE plpgsql;

-- call the batch done procedure here itself along with the store procedure
-- loading as this is the last step
SELECT batch_done_recon_f();

